Vue.component('Jia', {
	template: `
		<el-dialog title="数值加" width="500px" class="icon-dialog" :visible.sync="show" @open="open" :before-close="closeForm" append-to-body>
			<el-form :size="size" ref="form" :model="form" :rules="rules" label-width="70px">
				<el-row v-for="(item,index) in lists">
					<el-col :span="24">
						<el-form-item :label="item.name" :porp="item.name">
							<el-input-number controls-position="right" style="width:200px;" autoComplete="off" v-model="form.vals[index].money" clearable />
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button :size="size" :loading="loading" type="primary" @click="submit" >
					<span v-if="!loading">确 定</span>
					<span v-else>提 交 中...</span>
				</el-button>
				<el-button :size="size" @click="closeForm">取 消</el-button>
			</div>
		</el-dialog>
	`
	,
	components:{
	},
	props: {
		show: {
			type: Boolean,
			default: false
		},
		size: {
			type: String,
			default: 'small'
		},
		info: {
			type: Object,
		},
	},
	data(){
		return {
			form: {
				uid:'',
				vals:[],
			},
			loading:false,
			lists:{},
			rules: {
			}
		}
	},
	watch:{
		show(val){
			if(val){
				axios.post(base_url + '/Currency/available_currency').then(res => {
					if(res.data.status == 200){
						this.lists = res.data.data
						this.form.vals = [];
						this.lists.forEach(item=>{
							this.form.vals.push({money:'',name:item.name})
							console.log(this.form.vals[0].name)
						})
					}
				})
			}
		}
	},
	methods: {
		open(){
			this.form.uid = this.info.id
		},
		submit(){
			this.$refs['form'].validate(valid => {
				if(valid) {
					this.loading = true
					axios.post(base_url + '/Member/jia',this.form).then(res => {
						if(res.data.status == 200){
							this.$message({message: res.data.msg, type: 'success'})
							this.$emit('refesh_list')
							this.closeForm()
						}else{
							this.$message.error(res.data.msg)
						}
						this.loading = false
					}).catch(()=>{
						this.loading = false
					})
				}
			})
		},
		closeForm(){
			this.$emit('update:show', false)
			this.loading = false
			if (this.$refs['form']!==undefined) {
				this.$refs['form'].resetFields()
			}
		},
	}
})
